package com.cola.service;

import com.cola.dao.UserDao;
import com.cola.entity.Customer;
import com.cola.entity.User;
import com.cola.entity.WeChatInfo;
import org.apache.commons.lang3.StringUtils;

/**
 * @author Max
 * @since 2017/9/13
 */
public class UserService {
    private static volatile UserService instance = null;

    public static UserService getInstance() {
        if (instance == null) {
            synchronized (UserService.class) {
                if (instance == null) {
                    instance = new UserService();
                }
            }
        }
        return instance;
    }

    /**
     * 根据mobile获取用户信息
     * @param mobile
     * @return User
     * @author Max
     * @since 2017/9/13
     */
    public User getShopInfo(String mobile){
        return UserDao.getInstance().getShopInfo(mobile);
    }

    /**
     * 检查手机号是否被注册过
     * @param mobile
     * @return true:已经注册过;false:未注册
     * @author Max
     * @since 2017/9/13
     */
    public boolean checkMobile(String mobile,Integer customerId){
        return UserDao.getInstance().checkMobile(mobile,customerId);
    }

    /**
     * 检查手机号是否被注册过
     * @param mobile
     * @return true:已经注册过;false:未注册
     * @author Max
     * @since 2017/9/13
     */
    public boolean checkMobile(String mobile){
        return UserDao.getInstance().checkMobile(mobile);
    }

    /**
     * 更新用户微信信息
     * @return true:成功;false:失败
     * @author Max
     * @since 2017/9/14
     */
    public boolean updateUserWeChatInfo(WeChatInfo weChatInfo, String userType){
        return UserDao.getInstance().updateUserWeChatInfo( weChatInfo, userType);
    }


    /**
     * 更新用户微信信息
     * @param weChatInfo ;微信信息
     * @return
     * @author Max
     * @since 2017/9/14
     */
    public boolean updateWeChatInfo(WeChatInfo weChatInfo,String userType,String mobile){
        return UserDao.getInstance().updateWeChatInfo( weChatInfo, userType, mobile);
    }


    /**
     * 获取经销商或者配送员信息
     * @param mobile
     * @return User
     * @author Max
     * @since 2017/9/14
     */
    public User getMepInfo(String mobile){
        User user = new User();
        user = UserDao.getInstance().getMepInfo(mobile);
        if(user.getUserId()==null){
            user = UserDao.getInstance().getCourierInfo(mobile);
        }
        if(user.getUserId()!=null){
            return user;
        }
        return null;
    }



    /**
     * 检查用户信息是否正确
     * @param mobile,openId,userType
     * @return true false
     * @author Max
     * @since 2017/9/14
     */
    public boolean checkUserInfo(String mobile,String openId,String userType) {
        return StringUtils.isNotEmpty(mobile) && StringUtils.isNotEmpty(openId)
                && StringUtils.isNotEmpty(userType) && UserDao.getInstance().checkUserInfo(mobile, openId, userType);
    }


    /**
     * 根据店铺系统编号获取店铺信息
     * @param systemNo
     * @return Customer
     * @author Max
     * @since 2017/9/16
     */
    public Customer getCustomerInfoBySystemNo(String systemNo){
        return UserDao.getInstance().getCustomerInfoBySystemNo(systemNo);
    }

}
